package com.baozun.util;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * 
 * @Title:
 * @Company:宝尊电子商务有限公司
 * @Description:
 * @Author:xiaozhou.zhou
 * @Since:2015年1月19日
 * @Copyright:Copyright (c) 2014
 * @ModifyDate:
 * @Version:1.1.0
 */
public class SpringBeanUtil {

    /**
     * 通过request得到bean名称为key的对象
     * @param request
     * @param key
     * @return
     * @Description:
     */
    public static Object getBean(HttpServletRequest request, String key) {
        return getBean(request.getSession().getServletContext(), key);
    }

    public static Object getBean(ServletContext sc, String key) {
        ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(sc);
        return ac.getBean(key);
    }
}
